#include "stdafx.h"
#include "../GarbageCollector.h"
#include "../Managed.h"
#include "../Context.h"

namespace Gs
{
	// Initialises a new instance of the GarbageCollector class.
	GarbageCollector::GarbageCollector()
		: _head(0)
	{
	}

	// Destroys the instance.
	GarbageCollector::~GarbageCollector()
	{
		while(_head)
		{
			Managed *next = _head->_next;
			delete _head;
			_head = next;
		}
	}

	// Adds a new managed object to the garbage collector.
	void GarbageCollector::AddManagedObject(Managed *object)
	{
		object->_next = _head;
		_head = object;
	}

	// Manually marks a managed object before a collection cycle.
	void GarbageCollector::MarkManagedObject(Managed *object)
	{
		object->_state = Managed::Referenced;
	}

	// Performs a full garbage collection cycle.
	void GarbageCollector::Collect(Context *context)
	{
	}
}